#include "mykeyboard.h"


static void keyborad_1(void)
{
    lv_obj_t  *kb = lv_keyboard_create(lv_scr_act());
    //创建文本框
    lv_obj_t *ta = lv_textarea_create(lv_scr_act());    
    
    // 设置为数字键盘
    // lv_keyboard_set_mode(kb, LV_KEYBOARD_MODE_NUMBER);

    // 设置为大写字母键盘
    lv_keyboard_set_mode(kb, LV_KEYBOARD_MODE_TEXT_LOWER);

    //键盘与文本框关联    
    lv_keyboard_set_textarea(kb, ta);
}


lv_obj_t *kb;
static void event_cb(lv_event_t* e)
{
    lv_event_code_t code = lv_event_get_code(e);
    lv_obj_t* target = lv_event_get_target(e);
    
    if(code == LV_EVENT_PRESSED)
    {
        uint16_t id = lv_btnmatrix_get_selected_btn(target);
        const char* txt = lv_btnmatrix_get_btn_text(target, id);
        //判断点击的是键盘按钮
        if(strcmp(txt, LV_SYMBOL_KEYBOARD) == 0)
        {
            if(lv_keyboard_get_mode(target) == LV_KEYBOARD_MODE_NUMBER)
            {
                lv_keyboard_set_mode(target,LV_KEYBOARD_MODE_TEXT_LOWER);
                // lv_obj_set_size(kb, 400, 200);
            }
            else
            {
                lv_keyboard_set_mode(target,LV_KEYBOARD_MODE_NUMBER);
                lv_obj_set_size(kb, 400, 200);
            }
        }
    }
}
static void keyboard_2(void)
{
    kb = lv_keyboard_create(lv_scr_act());
    //创建文本框
    lv_obj_t *ta = lv_textarea_create(lv_scr_act());        
    //键盘与文本框关联    
    lv_keyboard_set_textarea(kb, ta);
    
    lv_obj_add_event_cb(kb, event_cb, LV_EVENT_ALL, NULL);
}


void mykeyboard_example(void)
{
    keyboard_2();
}